home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 095 / 151b_src.arc / QBARCV2.ASM < prev    next >
Assembly Source File  |  1987-02-27  |  29KB  |  907 lines

  1.         page    74,132
  2.         title   ARCV - Verbose ARC directory listing
  3.  
  4. ;       Special version of ARCV to be called by QB program
  5. ; usage:
  6. ;
  7. ;       CALL ARCV (Workname$,"filename[.ARC]", RETCD%)               ' CPC151AC
  8. ;
  9. ; notes:
  10. ;       This code originated from ARCV 1.15d - Verbose ARC directory display
  11. ;       written by V.Buerg and was modified to run as a called routine under
  12. ;       Microsoft QuickBasic.
  13. ;
  14. ;       Change 9/14/86 to dis-allow wildcards
  15. ;       Change 1/1/87 to recognize squash format
  16. ;       Change 2/18/87 to support network usage - - - - Jon Martin   ' CPC151A
  17.  
  18. print   macro   name                    ; display a field
  19.         mov     dx,offset name
  20.         call    prints
  21.         endm
  22.  
  23. printl  macro   text                    ; display a literal
  24.         local   txt,nxt
  25.         mov     dx,offset txt
  26.         call    prints
  27.         jmp     nxt
  28. txt     db      cr,lf,text
  29.         db      stopper
  30. nxt     equ     $
  31.         endm
  32.  
  33.  
  34. header  struc                           ; archive header
  35. mbrcode db      0                       ;  compression code
  36. mbrname db      13 dup (0)              ;  file name
  37. mbrsize dw      0,0                     ;  file size in archive
  38. mbrdate dw      0                       ;  creation date
  39. mbrtime dw      0                       ;  creation time
  40. mbrcrc  dw      0                       ;  cyclic redunancy check
  41. mbrlen  dw      0,0                     ;  true file size, bytes
  42. header  ends
  43.  
  44.  
  45. cseg    segment public para 'CODE'
  46.         assume  cs:cseg,ds:cseg,es:cseg
  47.  
  48.         public  arcv
  49. arcv    proc    far
  50.         push    bp                      ; save BASIC reg
  51.         mov     bp,sp                   ; get parameter list pointer
  52.         mov     cs:stkptr,sp            ; save stack ptr
  53.         mov     cs:saveds,ds            ; save QB seg reg
  54.         mov     cs:savees,es            ; save QB seg reg
  55.         mov     cs:errlvl,0             ; init return code
  56.         jmp     start                   ; do our thing
  57.  
  58. ;       return with error
  59.  
  60. error:  mov     ax,cs                   ; insure seg regs
  61.         mov     ds,ax                   ;  for proper exit
  62.         mov     es,ax
  63.         mov     sp,cs:stkptr
  64.         mov     errlvl,1                ; set bad return code
  65.         jmp     arcv2a                  ; produce totals anyway
  66.  
  67. ;       set DOS error level and exit
  68.  
  69. exit:   mov     sp,cs:stkptr            ; restore entry stack value
  70.  
  71.         mov     bx,word ptr cs:outhdl   ; close listing file
  72.         or      bx,bx                   ; if it was opened
  73.         jz      exiting
  74.         mov     ah,3eh
  75.         int     21h
  76. exiting:
  77.         push    ds                      ; restore QB dta
  78.         mov     dx,word ptr cs:savedta[2]
  79.         mov     ds,word ptr cs:savedta
  80.         mov     ah,1ah
  81.         int     21h
  82.         pop     ds
  83.  
  84.         mov     ds,word ptr cs:saveds   ; recover QB seg regs
  85.         mov     es,word ptr cs:savees
  86.         mov     al,cs:errlvl            ; get return code
  87.         cbw
  88.         mov     bp,sp                   ; parm ptr from entry
  89.         mov     di,word ptr 6[bp]       ; ptr to retcd variable
  90.         stosw
  91.         pop     bp
  92.         ret     6                       ; clear parms from stack     ' CPC151A
  93.  
  94.         subttl  '--- constants, equates and work areas'
  95.         page
  96.  
  97. cr      equ     13
  98. lf      equ     10
  99. bel     equ     7
  100. tab     equ     9
  101.  
  102. stopper equ     0               ; end of display line indicator
  103. arcmark equ     26              ; special archive marker
  104. arcver  equ     9               ; highest compression code used
  105.  
  106. stkptr  dw      0               ; stack pointer upon entry
  107. errlvl  db      0               ; dos error level returned
  108. flags   db      0               ; find-first return code
  109.  
  110. archdl  dw      0               ; file handle
  111.  
  112. arctitl db      cr,lf,'Archive:  '
  113. arcname db      76 dup (stopper)
  114.  
  115. fileptr dw      0               ; ptr to filename part of arcname
  116. savedta dw      0,0             ; addr of QB dta
  117. dta     db      48 dup (0)      ; data transfer area
  118.  
  119. saveds  dw      0               ; QB seg reg
  120. savees  dw      0               ; QB seg reg
  121. outhdl  dw      1               ; handle for output listing
  122. temp    db      76 dup (stopper); and temporary file name            ' CPC151A
  123.  
  124.         subttl  '--- i/o control variables'
  125.         page
  126.  
  127. inbufsz equ     512             ; size of input buffer
  128. inadr   dw      offset inbuf    ; offset to input buffer
  129. inptr   dw      offset inbuf    ; offset to current byte
  130. insize  dw      inbufsz         ; size of input buffer
  131. inlen   dw      0               ; bytes left in buffer
  132. incurh  dw      0               ; current file offset
  133. incurl  dw      0               ;  low word
  134.  
  135. usage   db      cr,lf
  136.         db      'QBARCV2 - Verbose ARC directory display for QuickBasic' ; ' CPC151A
  137.         db      cr,lf,lf,'  Usage:  call arcv (workname$,arcname[.ARC],result%' ; ' CPC151A
  138.         db      cr,lf,stopper
  139.  
  140. ;       display lines for verbose
  141.  
  142. vhdr    db      cr,lf
  143.         db      cr,lf,'Name          Length    Stowage    SF   Size now  Date       Time    CRC '
  144.         db      cr,lf,'============  ========  ========  ====  ========  =========  ======  ===='
  145.         db      stopper
  146.  
  147. vline   db      cr,lf
  148. vname   db      14 dup (' ')
  149. vlength db      '       0  '    ; length in archive
  150. vstyle  db      '          '    ; compression method
  151. vfactor db      ' xx%  '        ; compression factor
  152. vsize   db      10 dup (' ')    ; actual file bytes
  153. vdate   db      'dd '           ; creation date
  154.  vmonth db      'mmm '
  155.  vyear  db      'yy  '
  156.  vtime  db      'hh:mm   '      ; creation time
  157.  vcrc   db      'xxxx'          ; crc in hex
  158.         db      stopper
  159.  
  160. hundred dw      100             ; for computing percentages
  161. totsf   dw      0,0             ; average stowage factor
  162. totlen  dw      0,0             ; total of file lengths
  163. totsize dw      0,0             ; total of file sizes
  164. totmbrs dw      0               ; total number of files
  165.  
  166. ;       final totals line
  167.  
  168. vthdr   db      cr,lf,lf,'*Total    ' ;                            ' CPC151A
  169.  vtmbrs db      '    '
  170.  vtlen  db      8 dup (' '),'  '
  171.         db      10 dup (' ')
  172.  vtsf   db      '   %  '
  173.  vtsize db      8 dup (' ')
  174.         db      cr,lf           ; for tom
  175.         db      stopper
  176.  sign   db      ' '
  177.  
  178. styles  db      '  ----- '      ; 1 = old, no compression
  179.         db      '  ----- '      ; 2 = new, no compression
  180.         db      ' Packed '      ; 3 = dle for repeat chars
  181.         db      'Squeezed'      ; 4 = huffman encoding
  182.         db      'crunched'      ; 5 = lz, no dle
  183.         db      'crunched'      ; 6 = lz with dle
  184.         db      'Crunched'      ; 7 = lz with readjust
  185.         db      'Crunched'      ; 8 = lz with readjust and dle
  186.         db      'Squashed'      ; 9 = 13-bit lz with no dle
  187.  
  188. months  db      'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec '
  189.  
  190.         subttl  '--- mainline processing'
  191.         page
  192. ;
  193. ;       determine if command line or menu driven mode
  194.  
  195. start:
  196.         push    ds
  197.         mov     ax,cs                   ; set local seg regs
  198.         mov     ds,ax
  199.         mov     es,ax
  200.         mov     word ptr inlen,ax       ; initialize file variables
  201.         mov     word ptr incurh,ax
  202.         mov     word ptr incurl,ax
  203.  
  204.         push    cx                      ; bug fix
  205.         push    di                      ;   03-Feb-1987
  206.         cld                             ;   Steven M. Georgiades
  207.         mov     di,offset arcname
  208.         mov     al,0                    ;      Clears arcname for each call
  209.         mov     cx,76
  210.         rep     stosb
  211.         pop     di
  212.         pop     cx
  213.         pop     ds                      ;                            ' CPC151A
  214.         mov     si,word ptr 10[bp]      ; ptr to parameter vector    ' CPC151A
  215.         lodsw                           ; get string length          ' CPC151A
  216.         mov     cx,ax                   ;                            ' CPC151A
  217.         mov     si,word ptr [si]        ; get string offset          ' CPC151A
  218.         mov     di,offset temp          ;                            ' CPC151A
  219.  
  220. ;       copy first parameter                                         ' CPC151A
  221.  
  222. parm1:  lodsb                           ; copy filename              ' CPC151A
  223.         stosb                           ;                            ' CPC151A
  224.         loop    parm1                   ; loop until done            ' CPC151A
  225.         push    ds                      ;                            ' CPC151A
  226.         mov     ax,cs                   ; set local seg regs         ' CPC151A
  227.         mov     ds,ax                   ;                            ' CPC151A
  228.  
  229.         mov     dx,offset temp          ; open temporary file for output
  230.         mov     cx,0
  231.         mov     ah,3ch
  232.         int     21h
  233.         mov     outhdl,ax
  234.         pop     ds
  235.         jnc     parm2a                  ;                            ' CPC151A
  236.         mov     cs:errlvl,1             ; return error code
  237.         jmp     exit
  238.  
  239. parm2a: mov     si,word ptr 8[bp]       ; ptr to parameter vector
  240.         lodsw                           ; get string length
  241.         mov     cx,ax
  242.         mov     si,word ptr [si]        ; get string offset
  243.         or      cx,cx                   ; any operand?
  244.         jnz     parm2b                  ;                            ' CPC151A
  245.         print   usage
  246.         jmp     exit
  247.  
  248. ;       copy second parameter                                        ' CPC151A
  249.  
  250. parm2b:                                 ;                            ' CPC151A
  251.         mov     di,offset arcname
  252.  
  253. parm2c: lodsb                           ; copy filename              ' CPC151A
  254.         stosb
  255.         loop    parm2c                  ;                            ' CPC151A
  256.  
  257. ;       find filename part
  258.  
  259. parm2d:                                 ;                            ' CPC151A
  260.         mov     ax,cs                   ; need local seg regs
  261.         mov     ds,ax
  262.         mov     es,ax
  263.  
  264.         mov     si,offset arcname+75    ; end of filename stuff
  265.         std
  266.         mov     cl,76                   ; search for last path
  267. parm2e:                                 ;                            ' CPC151A
  268.         lodsb
  269.         cmp     al,'/'                  ; funny path delimiter?
  270.         je      parm2f                  ;                            ' CPC151A
  271.         cmp     al,'\'                  ; normal path delimiter?
  272.         je      parm2f                  ;                            ' CPC151A
  273.         cmp     al,':'                  ; bumped into drive?
  274.         je      parm2f                  ;                            ' CPC151A
  275.         loop    parm2e                  ;                            ' CPC151A
  276.         dec     si
  277. parm2f:                                 ;                            ' CPC151A
  278.         cld
  279.         add     si,2                    ; point to where filename goes
  280.         mov     fileptr,si              ; and save for later
  281.  
  282. ;       add default ARC extension if necessary
  283.  
  284.         mov     si,fileptr              ; start of filespec
  285.         mov     cx,13
  286. parm10:
  287.         lodsb
  288.         cmp     al,0                    ; end of name?
  289.         je      parm11
  290.         cmp     al,'.'                  ; got extension?
  291.         je      parm12
  292.         loop    parm10
  293. parm11:
  294.         mov     di,si                   ; ptr to end of name
  295.         dec     di
  296.         mov     ax,'A.'                 ; default extension
  297.         stosw
  298.         mov     ax,'CR'
  299.         stosw
  300.         mov     ax,0FF00h               ; append stoppers
  301.         stosw
  302. parm12:
  303.  
  304. ;       find first matching file
  305.  
  306. getfirst:
  307.         push    es
  308.         mov     ah,2fh                  ; get current dta ptr
  309.         int     21h                     ; returned in es:bx
  310.         mov     word ptr savedta,es
  311.         mov     word ptr savedta[2],bx
  312.         pop     es
  313.  
  314.         mov     dx,offset dta           ; set local dta for murkers
  315.         mov     ah,1ah
  316.         int     21h
  317.  
  318. ;       re-initialize
  319.  
  320. not_found:
  321.         sub     ax,ax                   ; reset totals counters
  322.         mov     totmbrs,ax
  323.         mov     totsize,ax
  324.         mov     totsize+2,ax
  325.         mov     totlen,ax
  326.         mov     totlen+2,ax
  327.         mov     totsf,ax
  328.         mov     inlen,ax
  329.         mov     incurl,ax
  330.         mov     incurh,ax
  331.         mov     dx,offset inbuf
  332.         mov     inptr,dx
  333.  
  334.         call    openarc                 ; see if archive exists
  335.         jnc     arcv1
  336.         jmp     exit
  337.  
  338.         page
  339. ;
  340. ;       process next archive header entry
  341.  
  342. arcv1:  print   arctitl
  343.         print   vhdr
  344.  
  345. arcvnext:
  346.         call    gethdr                  ; load next header
  347.         jnc     arcv2
  348.         jmp     exit                    ; all done
  349.  
  350. arcv2:  cmp     archdr.mbrcode,0        ; archive eof?
  351.         je      arcv2a
  352.         jmp     arcvgo
  353.  
  354. arcv2a:
  355.         mov     ax,totmbrs              ; total files
  356.         or      ax,ax                   ; are there any?
  357.         jnz     format_totals
  358.         jmp     skip_totals
  359.  
  360. format_totals:
  361.         sub     dx,dx
  362.         mov     si,offset vtmbrs-4
  363.         call    format
  364.  
  365.         mov     dx,totlen+2             ; total actual file size
  366.         mov     ax,totlen
  367.         mov     si,offset vtlen
  368.         call    format
  369.  
  370.         mov     dx,totsize+2            ; total achive file size
  371.         mov     ax,totsize
  372.         mov     si,offset vtsize
  373.         call    format
  374.  
  375. ; reduce the total size/length to word values
  376.  
  377.         mov     bx,totlen               ; get actual file size
  378.         mov     ax,totlen+2
  379.         mov     cx,totsize              ; length of file in archive
  380.         mov     dx,totsize+2
  381. arcv2b: or      ax,ax                   ; big number?
  382.         jz      arcv2c                  ; nope, can use it
  383.         shr     ax,1                    ; yup, divide by two
  384.         rcr     bx,1
  385.         shr     dx,1
  386.         rcr     cx,1
  387.         jmp     short arcv2b
  388.  
  389. arcv2c: mov     si,offset vtsf-5        ; format stowage factor
  390.         mov     ax,bx
  391.         mov     sign,' '                ; whata kludge
  392.         cmp     ax,cx                   ; arc is bigger than orig?
  393.         jb      arcv2c1
  394.         sub     ax,cx                   ; amount saved
  395.         jmp     short arcv2f
  396. arcv2c1:
  397.         sub     ax,cx
  398.         neg     ax
  399.         mov     sign,'-'
  400. arcv2f:
  401.         mul     hundred                 ; to percentage
  402.         add     ax,50
  403.         adc     dx,0                    ; round up percent
  404.         or      bx,bx                   ; empty file?
  405.         jnz     arcv2d
  406.         mov     ax,100
  407.         jmp     short arcv2e
  408.  
  409. arcv2d: div     bx
  410. arcv2e: sub     dx,dx
  411.         call    format
  412.  
  413.         mov     al,sign
  414.         mov     vtsf,al
  415.         print   vthdr                   ; display totals
  416.  
  417. skip_totals:
  418.         call    closarc
  419.         jmp     exit                    ;                            ' CPC151A
  420.  
  421.         page
  422. ;
  423. ;       format single line for each member
  424.  
  425. arcvgo:
  426.         mov     di,offset vname         ; copy file name
  427.         mov     si,offset archdr.mbrname
  428.         mov     cx,13
  429. arcv3:
  430.         lodsb
  431.         cmp     al,0                    ; end of name?
  432.         je      arcv4
  433.         stosb
  434.         loop    arcv3
  435.         jmp     short arcv5
  436. arcv4:
  437.         mov     al,' '                  ; pad with blanks
  438.         rep     stosb
  439. arcv5:
  440.         inc     totmbrs
  441.  
  442. ; reduce the size/length to word values
  443.  
  444.         mov     bx,archdr.mbrlen        ; get actual file size
  445.         mov     ax,archdr.mbrlen+2
  446.  
  447.         mov     cx,archdr.mbrsize       ; length of file in archive
  448.         mov     dx,archdr.mbrsize+2
  449.  
  450. arcv51: or      ax,ax                   ; big number?
  451.         jz      arcv52                  ; nope, can use it
  452.         shr     ax,1                    ; yup, divide by two
  453.         rcr     bx,1
  454.         shr     dx,1
  455.         rcr     cx,1
  456.         jmp     short arcv51
  457.  
  458. arcv52: mov     si,offset vfactor-5     ; format stowage factor
  459.         mov     ax,bx                   ; low word of actual size
  460.         mov     sign,' '
  461.         cmp     ax,cx                   ; arc member is larger?
  462.         jb      arcv520
  463.         sub     ax,cx                   ; amount saved
  464.         jmp     arcv56
  465. arcv520:
  466.         sub     ax,cx
  467.         neg     ax
  468.         mov     sign,'-'
  469. arcv56:
  470.         mul     hundred                 ; to percentage
  471.         add     ax,50
  472.         adc     dx,0                    ; round up percent
  473.         or      bx,bx                   ; empty file?
  474.         jnz     arcv53
  475.         mov     ax,100
  476.         jmp     short arcv54
  477.  
  478. arcv53: div     bx
  479. arcv54: sub     dx,dx
  480.         cmp     ax,100                  ; archive fouled?
  481.         jbe     arcv55
  482.         sub     ax,ax
  483. arcv55:
  484.         call    format
  485.         mov     al,sign
  486.         mov     vfactor,al
  487.  
  488.         sub     bx,bx                   ; determine style
  489.         mov     bl,archdr.mbrcode
  490.         mov     cl,3                    ; eight bytes each entry
  491.         shl     bx,cl
  492.         lea     si,styles-8[bx]         ; get ptr to style name
  493.         mov     di,offset vstyle
  494.         mov     cx,8
  495.         rep     movsb
  496.  
  497.         mov     si,offset vsize         ; format file size
  498.         mov     dx,archdr.mbrsize+2
  499.         mov     ax,archdr.mbrsize
  500.         add     totsize,ax
  501.         adc     totsize+2,dx
  502.         call    format
  503.  
  504.         mov     si,offset vlength       ; format file length
  505.         mov     dx,archdr.mbrlen+2
  506.         mov     ax,archdr.mbrlen
  507.         add     totlen,ax
  508.         adc     totlen+2,dx
  509.         call    format
  510.  
  511.         mov     ax,archdr.mbrdate       ; format file date
  512.         call    getdate
  513.  
  514.         mov     ax,archdr.mbrtime       ; format file time
  515.         call    gettime
  516.  
  517.         mov     ax,archdr.mbrcrc        ; format crc in hex
  518.         mov     di,offset vcrc
  519.         call    cvh
  520.  
  521.         print   vline                   ; display this file info
  522.  
  523.         mov     cx,word ptr archdr.mbrsize+2
  524.         mov     dx,word ptr archdr.mbrsize
  525.         add     dx,incurl               ; add current file offset
  526.         adc     cx,0
  527.         add     cx,incurh
  528.         mov     ax,4200h                ; skip over file data
  529.         mov     bx,archdl
  530.         int     21h
  531.         mov     incurh,dx               ; new position
  532.         mov     incurl,ax
  533.         mov     inlen,0                 ; reset read buffer
  534.         jmp     arcvnext
  535.  
  536.         subttl  ' - miscellaneous subroutines'
  537.         page
  538.  
  539. openarc proc    near                    ; open new archive
  540.         push    bx
  541.         mov     byte ptr errlvl,0
  542.         mov     dx,offset arcname
  543.         mov     ax,3d00h                ; for input
  544.         int     21h
  545.         jc      openerr
  546.         mov     archdl,ax               ; save file handle
  547.         clc
  548.         pop     bx
  549.         ret
  550. openerr:
  551.         printl  'Unable to open archive: '
  552.         print   arcname
  553.         jmp     error
  554. openarc endp
  555.  
  556.  
  557. closarc proc    near
  558.         push    bx
  559.         mov     bx,archdl               ; previous handle
  560.         or      bx,bx                   ; already open?
  561.         jz      closed
  562.         mov     ah,3eh                  ; yes, so close it
  563.         int     21h
  564. closed: mov     archdl,0
  565.         pop     bx
  566.         ret
  567. closarc endp
  568.  
  569. ;
  570. ;       print string like int 21h function 9
  571.  
  572. prints  proc    near                    ; dx has offset to string
  573.         push    si                      ;  ending in char x'ff'
  574.         push    bx
  575.         push    cx
  576.         mov     si,dx
  577.         sub     cx,cx
  578. ps1:    lodsb
  579.         cmp     al,stopper              ; ending hex ff?
  580.         je      ps9
  581.         inc     cx                      ; incr text length
  582.         jmp     ps1
  583.  
  584. ps9:    mov     ah,40h                  ; write to file
  585.         mov     bx,outhdl               ; using std out or temp file
  586.         int     21h
  587.  
  588.         pop     cx                      ; recover registers
  589.         pop     bx
  590.         pop     si
  591.         ret
  592. prints  endp
  593.  
  594.         page
  595. ;
  596. ;       format the time
  597.  
  598. time    record  hour:5,min:6,sec:5      ;packed time
  599.  
  600. gettime proc    near                    ;format the date
  601.         mov     di,offset vtime
  602.         or      ax,ax                   ;it is zero?
  603.         jz      gottime
  604.         push    ax                      ;save date
  605.         and     ax,mask hour            ;get hour part
  606.         mov     cl,hour                 ;bits to shift
  607.         shr     ax,cl
  608.         call    cnvrt1
  609.         stosw
  610.         mov     al,':'
  611.         stosb
  612.  
  613. gt3:    pop     ax                      ;get the time back
  614.         and     ax,mask min             ;get min part
  615.         mov     cl,min                  ;bits to shift
  616.         call    cnvrt
  617.         stosw
  618. gottime:ret
  619. gettime endp
  620.  
  621. cnvrt2  proc    near                    ;convert to ascii
  622.         call    cnvrt
  623.         cmp     al,'0'                  ;suppress leading zero
  624.         jne     cnvrtd
  625.         mov     al,' '
  626.         ret
  627.  
  628. cnvrt:  shr     ax,cl
  629. cnvrt1: aam                             ;make al into bcd
  630.         or      ax,'00'                 ; and to ascii
  631.         xchg    al,ah
  632. cnvrtd: ret
  633. cnvrt2  endp
  634.  
  635.         page
  636. ;
  637. ;       format the date
  638.  
  639. date    record  yr:7,mo:4,dy:5          ;packed date
  640.  
  641. getdate proc    near                    ;format the date
  642.         or      ax,ax                   ;is it zero?
  643.         jz      gotdate
  644.         push    ax                      ;save date
  645.         and     ax,mask yr              ;get year part
  646.         mov     cl,yr                   ;bits to shift
  647.         call    cnvrt
  648.         mov     di,offset vyear
  649.         or      al,'8'                  ;adjust for base year
  650.         stosw
  651.  
  652.         pop     bx                      ;get the date back
  653.         push    bx                      ;save it
  654.         and     bx,mask mo              ;get month part
  655.         mov     cl,mo                   ;bits to shift
  656.         shr     bx,cl
  657.         add     bx,bx                   ; form month table index
  658.         add     bx,bx
  659.         lea     si,word ptr months-4[bx]
  660.         mov     cx,3
  661.         mov     di,offset vmonth
  662.         rep     movsb
  663.  
  664.         pop     ax                      ;get the date back
  665.         and     ax,mask dy              ;get day part
  666.         mov     cl,dy                   ;bits to shift
  667.         call    cnvrt
  668.         mov     di,offset vdate
  669.         stosw
  670. gotdate:ret
  671. getdate endp
  672.  
  673.         page
  674. ;
  675. ; ripped from sdir.asm. how does this work?
  676.  
  677. ddptr   dw      0
  678.  
  679. format  proc    near    ;formats a 32 bit integer in dx:ax
  680.         push    bp      ; to ds:si
  681.         push    bx
  682.         push    di
  683.         push    si
  684.         mov     ddptr,si        ;addr of target field
  685.         mov     di,dx           ;routine uses di:si
  686.         mov     si,ax
  687.         call    printdd
  688.         pop     si
  689.         pop     di
  690.         pop     bx
  691.         pop     bp
  692.         ret
  693.  
  694. printdd:
  695.         xor     ax,ax           ;zero out the
  696.         mov     bx,ax           ; working
  697.         mov     bp,ax           ; registers.
  698.         mov     cx,32           ;# bits of precision
  699. j1:     shl     si,1
  700.         rcl     di,1
  701.         xchg    bp,ax
  702.         call    j6
  703.         xchg    bp,ax
  704.         xchg    bx,ax
  705.         call    j6
  706.         xchg    bx,ax
  707.         adc     al,0
  708.         loop    j1
  709.         mov     cx,1710h
  710.         mov     ax,bx
  711.         call    j2
  712.         mov     ax,bp
  713. j2:     push    ax
  714.         mov     dl,ah
  715.         call    j3
  716.         pop     dx
  717. j3:     mov     dh,dl
  718.         shr     dl,1            ;move high
  719.         shr     dl,1            ; nibble to
  720.         shr     dl,1            ; the low
  721.         shr     dl,1            ; position.
  722.         call    j4
  723.         mov     dl,dh
  724. j4:     and     dl,0fh          ;mask low nibble
  725.         jz      j5              ;if not zero
  726.         mov     cl,0
  727. j5:     dec     ch
  728.         and     cl,ch
  729.         or      dl,'0'          ;fold in ascii zero
  730.         sub     dl,cl
  731.         mov     bx,ddptr
  732.         mov     [bx],dl         ;ptr to next target field
  733.         inc     ddptr
  734.         ret
  735.  
  736. j6:     adc     al,al
  737.         daa
  738.         xchg    al,ah
  739.         adc     al,al
  740.         daa
  741.         xchg    al,ah
  742.         ret
  743. format  endp
  744.  
  745.         page
  746. cvh     proc    near            ; convert 16-bit binary word in ax
  747.         push    di              ; to hex ASCII string at ds:di
  748.         push    bx              ; save registers
  749.         push    cx
  750.         push    dx
  751.  
  752.         mov     dx,ax           ; save 16-bits
  753.  
  754.         mov     bl,dh           ; third nibble
  755.         mov     cl,4
  756.         shr     bl,cl
  757.         mov     al,hexchar[bx]
  758.         stosb
  759.  
  760.         mov     bl,dh           ; last nibble
  761.         and     bl,0fh
  762.         mov     al,hexchar[bx]
  763.         stosb
  764.  
  765.         mov     bl,dl           ; first nibble
  766.         mov     cl,4
  767.         sub     bh,bh
  768.         shr     bl,cl           ; isolate
  769.         mov     al,hexchar[bx]
  770.         stosb
  771.  
  772.         mov     bl,dl           ; second nibble
  773.         and     bl,0fh          ; isolate
  774.         mov     al,hexchar[bx]
  775.         stosb
  776.         pop     dx              ; restore registers
  777.         pop     cx
  778.         pop     bx
  779.         pop     di
  780.         ret                     ; return
  781.  
  782. hexchar db      '0123456789ABCDEF'
  783. cvh     endp
  784.  
  785.         subttl  ' - i/o subroutines'
  786.         page
  787.  
  788. getc    proc    near                    ; return next byte in al
  789.         push    si                      ;  or cf=1 for eof
  790. getc1:
  791.         dec     inlen                   ; any left in buffer
  792.         jge     getc2                   ; yes, pick it up
  793.         call    getblk
  794.         jnc     getc1
  795.         pop     si                      ; return cf=1 at eof
  796.         ret
  797. getc2:
  798.         mov     si,inptr                ; offset to next byte
  799.         lodsb
  800.         mov     inptr,si
  801.         add     incurl,1                ; bump file offset
  802.         adc     incurh,0
  803.         pop     si
  804.         ret
  805. getc    endp
  806.  
  807.  
  808. getblk  proc    near                    ; read next block
  809.         push    bx
  810.         push    cx
  811.         push    dx
  812.         mov     ah,3fh                  ; read from handle
  813.         mov     bx,archdl               ; arc file handle
  814.         mov     cx,inbufsz              ; input buffer size
  815.         mov     dx,offset inbuf         ; offset to input buffer
  816.         mov     inptr,dx
  817.         int     21h
  818.         jc      getblkr                 ; oops
  819.         or      ax,ax                   ; anything read?
  820.         jnz     getblka
  821.         stc                             ; no, set cf=1 for eof
  822.         jmp     short getblkx           ; and exit
  823. getblka:
  824.         mov     inlen,ax                ; return count of bytes read
  825. getblkx:
  826.         pop     dx
  827.         pop     cx
  828.         pop     bx
  829.         ret
  830.  
  831. getblkr:
  832.         printl  'I/O error reading '
  833.         print   arcname
  834.         jmp     error                   ; gotta quit
  835. getblk  endp
  836.  
  837.         subttl  '--- load next archive header'
  838.         page
  839.  
  840. gethdr  proc    near
  841.         mov     cx,132                  ; gotta look for the damn thing
  842. gethdr2:
  843.         call    getc                    ; get next file byte
  844.         jc      gethdrr1                ; premature eof
  845.         cmp     al,arcmark              ; start of header?
  846.         je      gethdr3                 ; yup, let's start cookin
  847.         loop    gethdr2
  848. gethdrr1:
  849.         printl  'Invalid archive format!'
  850.         jmp     error
  851.  
  852. gethdr3:
  853.         call    getc                    ; get version code
  854.         jc      gethdrr1
  855.         mov     archdr.mbrcode,al
  856.         cmp     al,arcver               ; reasonable code?
  857.         ja      gethdrr1                ; nope, funny stuff
  858.         cmp     al,0                    ; archive eof?
  859.         je      gethdr9                 ; yup done
  860.  
  861.         mov     cx,13                   ; get member name
  862.         mov     di,offset archdr.mbrname
  863. gethdr4:
  864.         call    getc
  865.         jc      gethdrr1
  866.         stosb
  867.         loop    gethdr4
  868. gethdr5:
  869.         mov     cx,10                   ; length remaining
  870.         cmp     archdr.mbrcode,1        ; old format?
  871.         je      gethdr6                 ; yes, it's short
  872.         mov     cl,14
  873. gethdr6:
  874.         mov     di,offset archdr.mbrsize
  875. gethdr7:
  876.         call    getc
  877.         jc      gethdrr1
  878.         stosb
  879.         loop    gethdr7
  880. gethdr8:
  881.         cmp     archdr.mbrcode,1        ; old format?
  882.         jne     gethdr9                 ; if so, it's short
  883.         mov     si,offset mbrsize
  884.         mov     di,offset mbrlen
  885.         mov     cx,4
  886.         rep     movsb
  887. gethdr9:
  888.         clc
  889.         ret
  890.  
  891. gethdrr2:
  892.         printl  'Invalid archive header'
  893.         jmp     error
  894. gethdr  endp
  895.  
  896.         subttl  '--- i/o data areas'
  897.         page
  898.  
  899. arcv    endp
  900.  
  901. archdr  db      64 dup (0)              ; i/o area for a header
  902.  
  903. inbuf   db      inbufsz dup (0)
  904.  
  905. cseg    ends
  906.         end     arcv
  907.